package com.lepu.app.fun.my.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.app.utils.DateUtil;
import com.core.lib.application.BaseFragmentActivity;
import com.core.lib.utils.photo.UniversalImageLoadTool;
import com.core.lib.widget.CircularImageView;
import com.eyzhs.app.R;
import com.lepu.app.fun.mother_circle.bean.BeanMotherMessage;
import com.lepu.app.fun.my.bean.BeanMessage;
import com.lepu.app.usercenter.UserOtherInfoActivity;

import java.util.ArrayList;

@SuppressWarnings("unused")
public class MessageFriendAdapter extends BaseAdapter {

    private LayoutInflater mLayoutInflater = null;
    private Context mContext = null;
    private ArrayList<BeanMessage> mArrayList = null;

    public MessageFriendAdapter(Context context,ArrayList<BeanMessage> arrayList) {
        mContext = context;
        mLayoutInflater = LayoutInflater.from(context);
        mArrayList = arrayList;
    }

    @Override
    public int getCount() {
        return mArrayList.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressLint("InflateParams")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {
            convertView = mLayoutInflater.inflate(R.layout.message_friend_item, null);
            holder = new ViewHolder();
            holder.itemLayout = (LinearLayout) convertView.findViewById(R.id.itemLayout);
            holder.newIc = (ImageView) convertView.findViewById(R.id.newIc);
            holder.headIc = (CircularImageView) convertView.findViewById(R.id.headIc);
            holder.name = (TextView) convertView.findViewById(R.id.name);
            holder.content = (TextView) convertView.findViewById(R.id.content);
            holder.time = (TextView) convertView.findViewById(R.id.time);
          

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        final BeanMessage item = mArrayList.get(position);
        UniversalImageLoadTool.disPlay(item.Avatar, holder.headIc, R.drawable.app_ic_default_avatar_64);
        holder.newIc.setVisibility(item.IsRead == 1 ? View.INVISIBLE : View.VISIBLE);
        
        holder.name.setText(item.UserNickName);
        //holder.content.setText(item.MessageContent);
        holder.time.setText(DateUtil.getHMTime(item.MessageTime));
        holder.itemLayout.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				Intent intent = new Intent(mContext,UserOtherInfoActivity.class);
				intent.putExtra("targetId", item.UserID);
				((BaseFragmentActivity)mContext).startActivity(intent,true);
			}
		});
      
        return convertView;
    }

    private static class ViewHolder {
    	LinearLayout itemLayout;
        ImageView newIc;
        CircularImageView headIc;
        TextView name;
        TextView content;
        TextView time;
    }

}
